package com.shaoshaohuo.app.view;

import android.support.v4.view.ViewPager;
import android.view.View;

/**
 * Created by Administrator on 2017/6/8.
 */

public class DefaultTransformer implements ViewPager.PageTransformer {

    @Override
    public void transformPage(View view, float position) {
        float alpha = 0;
        if (0 <= position && position <= 1) {
            alpha = 1 - position;
        } else if (-1 < position && position < 0) {
            alpha = position + 1;
        }
//        view.setAlpha(alpha);
        view.setTranslationX(view.getWidth() * -position);
        float yPosition = position * view.getHeight();
        view.setTranslationY(yPosition);
        if (transformerListener != null) {
            transformerListener.transformapge(view, position);
        }

    }

    private TransformerListener transformerListener;

    public void setTransformerListener(TransformerListener transformerListener) {
        this.transformerListener = transformerListener;
    }

    public interface TransformerListener {
        void transformapge(View view, float position);

    }
}